<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
</head>
<body>

<img id="img" src="img/banner_1.jpg" width="100%">


<script>

  // 修改图片 src 属性
  var number = 1;
  var img = document.getElementById("img");
  function fun() {
    number++;
    // 判断 number 是否大于3
    if (number > 3) {
      number = 1;
    }
    if (img) {
      img.src = "img/banner_" + number + ".jpg";
    }
  }

  // 定时器
  setInterval(fun, 3000);

</script>

</body>
</html>